package inner_class;

interface Incrementable {
    void increment();
}

class Increment1 implements Incrementable {
    private int i = 0;

    @Override
    public void increment() {
        i ++;
        System.out.println(i);
    }
}

class MyIncrement {
    private int i = 0;
    public void increment() {
        System.out.print("my increment ");
        i ++;
        System.out.println(i);
    }
}

class MyIncrement1 extends MyIncrement {
    class MyIncrementer implements Incrementable {
        @Override
        public void increment() {
            MyIncrement1.this.increment();
        }
    }
    MyIncrementer myIncrementer() {
        return new MyIncrementer();
    }
}

class Selector {
    private Incrementable incrementable;
    public Selector(Incrementable incrementable) {
        this.incrementable = incrementable;
    }
    public void go() {
        incrementable.increment();
    }
}

/**
 * 回调
 */
public class CallbackDemo {
    public static void main(String[] args) {
        new Selector(new Increment1()).go();
        new Selector(new MyIncrement1().myIncrementer()).go();
    }
}
